package cn.com.open.errorquestion.mapper;

import cn.com.open.errorquestion.model.AnswerQuestionLog;
import cn.com.open.errorquestion.provider.AnswerQuestionLogProvider;
import org.apache.ibatis.annotations.*;

@Mapper
public interface AnswerQuestionLogMapper {


    /**
     * 保存作答记录
     * @param answerData
     */
    @Insert("INSERT INTO answer_question_log_${tableNumber}\n" +
            " (id,organizationId,examineeId,courseId,knowledgePointId,paperId,questionId,questionType,questionDifficult,trueCount,falseCount,createTime)\n" +
            " VALUES\n" +
            " (#{id},#{organizationId},#{examineeId},#{courseId},#{knowledgePointId},#{paperId},#{questionId},#{questionType},#{questionDifficult},#{trueCount},#{falseCount},now())")
    void save(AnswerQuestionLog answerData);

    @Update("UPDATE answer_question_log_${tableNumber} SET trueCount=#{trueCount},falseCount=#{falseCount} \n" +
            "WHERE id=#{id}" +
            "")
    void update(AnswerQuestionLog answerData);

    /**
     * 不分表
     * @param answerData
     * @return
     */
//    @SelectProvider(type = AnswerQuestionLogProvider.class,method = "findOne")
//    AnswerQuestionLog findOne(AnswerQuestionLog answerData);


    /**
     * 分表 将试卷单独提出
     * @param answerData
     * @return
     */
    @Select("SELECT * FROM answer_question_log_${tableNumber} WHERE 1=1 \n" +
            " AND organizationId = #{organizationId}" +
            " AND examineeId = #{examineeId}" +
            " AND questionId = #{questionId}" +
            " LIMIT 1")
    AnswerQuestionLog findOne(AnswerQuestionLog answerData);
}
